package team.archai.nexus.boot.web.handlers;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;
import team.archai.nexus.boot.constant.HttpEnum;
import team.archai.nexus.boot.tool.HttpUtil;
import team.archai.nexus.boot.web.response.ResultUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @program: tiny-dust-boot-build
 * @description: 未登录
 * @author: lishibin
 * @create: 2020-07-11 11:07
 **/
@Component
@ConditionalOnProperty(name = "archai-nexus.auth.type", havingValue = "security")
public class AuthenticationHandler implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) {
        HttpUtil.responseJson(response, ResultUtil.out(HttpEnum.UNAUTHORIZED));
    }
}
